package com.yang.singleton;

/*
* 静态内部类
* 加载外部类时不会加载内部类，这样可以实现懒加载，JVM保证线程安全，类只加载一次
* */
public class Singleton7 {


    //构造方法私有化
    private Singleton7(){}



    private static class Singleton7Holder {
        private static final Singleton7 INSTANCE = new Singleton7();
    }
    public static Singleton7 getInstance() {
        return Singleton7Holder.INSTANCE;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 50; i++) {
            new Thread(() -> {
                System.out.println(Singleton7.getInstance().hashCode());
            }).start();
        }
    }
}


